import {axios} from '../utils/request'
import {ORDER_MODULE} from './_prefix'


type rating = {
    orderID : number
    rating : number
    commentContent : string
}

type orderCreateInfo = {
    commodityID : number
    deliveryMethod : number
    quantity : number
}

type orderPay = {
    orderID : number,
    couponID : number[]
}

type page = {
    page: number,
    pageSize: number
}
//创建订单
export const orderCreate = (orderCreate : orderCreateInfo) => {
    return axios.post(`${ORDER_MODULE}/create`,orderCreate,{headers: {'Content-Type': 'application/json'}})
        .then(res => {
            return res;
        })
}

//支付
export const pay = (payInfo : orderPay) => {
    return axios.post(`${ORDER_MODULE}/pay`,payInfo,{headers: {'Content-Type': 'application/json'}})
        .then(res => {
            return res;
        })
}

//获取全部订单信息
export const orderInfo = (page: page) => {
    return axios.post(`${ORDER_MODULE}/info`,null,{params: page})
        .then(res =>{
            return res
        })
}

//通过订单id获取订单信息
export const orderSingleInfo = (orderId : number) =>{
    return axios.post(`${ORDER_MODULE}/info/single`,null,{params:{id : orderId}})
        .then(res => {
            return res;
        })
}

//发货
export const dispatch = (orderId : number) =>{
    return axios.post(`${ORDER_MODULE}/dispatch`,null,{params:{orderID : orderId}})
        .then(res => {
            return res;
        })
}

//收货
export const receive = (orderId : number) =>{
    return axios.post(`${ORDER_MODULE}/receive`,null,{params:{orderID : orderId}})
        .then(res => {
            return res;
        })
}

//评价
export const rate = (rating : rating) =>{
    return axios.post(`${ORDER_MODULE}/comment`,rating,{headers: {'Content-Type': 'application/json'}})
        .then(res => {
            return res;
        })
}

//通过订单id获得评价信息
export const getCommentById = (orderId : number) =>{
    return axios.post(`${ORDER_MODULE}/get_comment`,null,{params:{id : orderId}})
        .then(res => {
            return res;
        })
}

//下载excel
export const downloadExcel = () =>{
    return axios.get(`${ORDER_MODULE}/excel`)
        .then(res => {
            return res;
        })
}